/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2010
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
 *
 * Filename:
 * ---------
 *  IdleAdapter.c
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  This file implements the adapter after the idle revision.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
 * Include
 ****************************************************************************/

#include "MMI_include.h"

#include "IdleHomescreen.h"
#include "BrowserGprots.h"
#include "SimDetectionProt.h"
#include "SimDetectionGexdcl.h"
#include "SimDetectionGprot.h"
#include "BrowserGprots.h"
#include "NetworkSetupDefs.h"
#include "NetworkSetupGProt.h"
#include "GeneralDeviceGprot.h"
#include "AlarmFrameworkProt.h"
#include "PowerOnChargerProt.h"
#include "SATGProts.h"
#include "IdleAppGprot.h"
#include "IdleAppProt.h"
#include "IdleGprot.h"
#include "IdleAppDef.h"
#include "IdleAppResDef.h"
#include "PersonalizationProt.h"
#include "SSCStringHandle.h"
#include "PhoneSetupGprots.h"
#include "ScrLockerGprot.h"
#include "UcmSrvGprot.h"
#include "UcmGprot.h"
#include "PhbCuiGprot.h"
#include "VoIPResDef.h"
#include "SimCtrlSrvGprot.h"
#include "BootupSrvGprot.h"
#include "IdleProt.h"

#include "MMSAppInterfaceGprot.h"
#include "DialerGprot.h"
#include "NITZ.h"

extern void DeInitSpecialMode(void);

extern void mmiapi_enter_idle_screen_notify(void);

extern void MMIProcessActionMsg(void);

#if defined(__DIRECT_ENTRY_FACTORY_MODE_ON_BOOTUP__)
extern MMI_BOOL DirectMode;
#endif

#ifdef __SAT__
#ifndef __SAT_LOWCOST_UI_DISABLE__
extern void SATEVDLIdleScreenAvaliable(void);
#endif
#endif

#ifdef __CERTMAN_SUPPORT__
#include "CertManMMIGprots.h"
#endif

#ifdef __J2ME__
#include "javaAgencyGprot.h"
#include "jam_internal.h"
#endif /* __J2ME__ */

#ifdef __MOD_SMSAL__
#include "MessagesExDcl.h"
#endif /* __MOD_SMSAL__ */

#ifdef __MMI_POC__
#include "PoCGProt.h"
#endif

#ifdef __MMI_DUAL_SIM_MASTER__
#include "MTPNP_AD_master_header.h"
#endif

#ifdef WAP_SUPPORT
#include "Wapadp.h"
#include "wap_ps_struct.h"
#endif 

#ifdef __MMI_DSM_NEW__
#include "mrp_include.h"
#endif

/****************************************************************************
 * Obsolete global variable
 ****************************************************************************/

idle_context_struct g_idle_context = 
{
    0,                      /* IsOnIdleScreen */
    SUBLCD_NOT_ON_IDLE,     /* IsSubLcdOnIdleScreen */
    0,                      /* IsOnDialerScreen */
    0,                      /* IsOnSimErrorScreen */
    0,                      /* IsOnSimErrorDialerScreen */
    0,                      /* IsScrSvrSleepIn */
    0,                      /* IsRSKPressOnScreenSaver */
    0,                      /* LongPressEnable */
    0,                      /* ScreenSaverRunFlag */
    0,                      /* ToNameScrFromIdleApp */
#ifdef __MMI_KEYPAD_LOCK_PATTERN_2__
    0,                      /* ToMainMenuScrFromIdleApp */
#endif 
    0,                      /* RskPressedFromIdleApp */
    0,
    -1,                     /* IdleScreenDigitKeyCode */
#ifdef __MMI_SIMAP_SUPPORT__
    0,
#endif
#ifdef __OP12__
    NULL,                   /* delayed_rsk_hdlr */
#endif
#ifdef __MMI_IDLE_SCREEN_ICON_SHORTCUT__
    {0},                    /* icon_shortcut_hdlr */
#endif
    0,                      /* AutoLockTimeOut */
    0,                      /* cui_save_number_id */
    {0}                     /* All dialled digits from idle screen */
};

idle_keylock_struct g_keylock_context = 
{
    0,      /* gKeyPadLockFlag */
    0,
    0,      /* KeyLockLSKStringID */
    0,      /* KeyLockRSKStringID */
    0,      /* KeyLockLSKIconID */
    0,      /* KeyLockRSKIconID */
    NULL    /* diamond, 2006/03/26 Generic exit function for keypad lock callback screens */
};


/****************************************************************************
 * Function
 ****************************************************************************/

mmi_ret mmi_idle_handle_idle_group_enter(mmi_event_struct *evt)
{
    static MMI_BOOL is_idle_init_done = MMI_FALSE;

#ifdef __MMI_OP11_HOMESCREEN__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* __MMI_OP11_HOMESCREEN__ */

    //DinitHistory();
    DeInitSpecialMode();    /* EngineerMode/Factory Deinit */

    mmi_idle_set_eg_events();

#ifdef __J2ME__
    jam_enter_idle_screen_notify();
#endif

    mmiapi_enter_idle_screen_notify();

#ifdef __SAT__
#ifndef __SAT_LOWCOST_UI_DISABLE__
    SATEVDLIdleScreenAvaliable();
#endif
#endif

    if (!is_idle_init_done)
    {
        TurnOffBacklight();

    #if defined(__DIRECT_ENTRY_FACTORY_MODE_ON_BOOTUP__)
        DirectMode = MMI_FALSE;
    #endif

        PendingAlarmReminder();
        StartLEDPatternBackGround();

    #ifdef __MMI_POC__
        if (g_pwr_context.CurrentServiceType == FULL_SERVICE)
        {
            mmi_poc_poweron_reg();
        }
    #endif /* __MMI_POC__ */

    #if defined(OBIGO_Q03C) && defined(WAP_SUPPORT)
        MMIProcessActionMsg();
    #endif
        mmi_sim_rearrange_menu_item();

    #ifdef __MMI_NETSET_3G_ENHANCE__
    #ifdef __MMI_WLAN_FEATURES__
        /* GSM is turn on */
        if (mmi_netset_get_active_preferred_mode() != P_WLAN_ONLY)
    #endif /* __MMI_WLAN_FEATURES__ */
        {
            /* SIM is valid */
            if (mmi_bootup_is_sim_valid())
            {
                mmi_netset_3g_nocell_start_timer();
            }
        }
    #endif /* __MMI_NETSET_3G_ENHANCE__ */

    #ifdef __MMI_AUTO_ANSWER_MACHINE__
        mmi_autoam_init_statusicon();
    #endif

        is_idle_init_done = MMI_TRUE;
    }

#ifdef __SAT__
    if (GetPostponedSATScreen())
    {
        (*GetPostponedSATScreen())();
        ClearPostponedSATScreen();
    }
#endif /* __SAT__ */

    return MMI_RET_OK;
}


mmi_ret mmi_idle_handle_idle_group_exit(mmi_event_struct *evt)
{
    return MMI_RET_OK;
}


mmi_ret mmi_idle_handle_idle_enter(mmi_event_struct *evt)
{
    g_idle_context.IsOnIdleScreen = 1;
    g_idle_context.IsOnSimErrorScreen = 1;

    if (mmi_bootup_get_active_flight_mode() == FLIGHTMODE_SILENT)
    {
        StopLEDPatternNoService();
        
        /* reset icons to indicate no service available */
        wgui_status_icon_bar_change_icon_level(STATUS_ICON_SIGNAL_STRENGTH, 0);
        wgui_status_icon_bar_change_icon_level(STATUS_ICON_SUBLCD_SIGNAL_STRENGTH, 0);
        IdleResetStatusIcon(STATUS_ICON_ROAMING);
    }

    return MMI_RET_OK;
}


mmi_ret mmi_idle_handle_idle_exit(mmi_event_struct *evt)
{
    g_idle_context.IsOnIdleScreen = 0;
    g_idle_context.IsOnSimErrorScreen = 0;


#ifdef __MMI_DSM_NEW__
#if(MTK_VERSION < 0x11B1132)
{
	if(MR_SUCCESS == mr_app_system_event_hdlr(MR_SYSMSG_EXIT_IDLESCREEN, 0, 0))
		return MMI_RET_OK;
}
#endif
#endif

    return MMI_RET_OK;
}


mmi_ret mmi_idle_handle_bootup_completed(mmi_event_struct *event)
{
    mmi_idle_notify_bootup_ready_to_l4c(); /* to L4C */

    return MMI_RET_OK;
}


mmi_ret mmi_idle_handle_sim_ctrl_availability_changed(mmi_event_struct *event)
{
    srv_sim_ctrl_availability_changed_evt_struct *evt;

    MMI_ASSERT(event);

    evt = (srv_sim_ctrl_availability_changed_evt_struct *)event;

    if (evt->sim == MMI_SIM1)
    {
        mmi_idle_notify_dual_sim_status_to_spa_from_sim1();
    }
    else
    {
        mmi_idle_notify_dual_sim_status_to_spa_from_sim2();
    }

    mmi_idle_notify_dual_sim_status_to_wap();

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  IdleSetStatusIcon
 * DESCRIPTION
 *  Show Icon
 * PARAMETERS
 *  index       [IN]
 *  U8(?)       [IN]
 * RETURNS
 *  void
 *****************************************************************************/
void IdleSetStatusIcon(S16 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_status_icon_bar_show_icon(index);
}


/*****************************************************************************
 * FUNCTION
 *  IdleResetStatusIcon
 * DESCRIPTION
 *  Hide Icon
 * PARAMETERS
 *  index       [IN]
 *  U8(?)       [IN]
 * RETURNS
 *  void
 *****************************************************************************/
void IdleResetStatusIcon(S16 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_status_icon_bar_hide_icon(index);
}


/*****************************************************************************
 * FUNCTION
 *  IsChineseSet
 * DESCRIPTION
 *  This function checks whether the current language is set as Chinese or not.
 * PARAMETERS
 *  void
 * RETURNS
 *  On yes, return MMI_TRUE; otherwise, return MMI_FALSE.
 *****************************************************************************/
pBOOL IsChineseSet(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    extern sLanguageDetails *gLanguageArray;
    extern U16 gCurrLangIndex;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_TCHINESE) == 0)
    {
        return 1;
    }

    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_SCHINESE) == 0)
    {
        return 1;
    }

    return 0;
}

/*****************************************************************************
 * FUNCTION
 *  IsEnglishSet
 * DESCRIPTION
 *  This function checks whether the current language is set as English or not.
 * PARAMETERS
 *  void
 * RETURNS
 *  On yes, return MMI_TRUE; otherwise, return MMI_FALSE.
 *****************************************************************************/
pBOOL IsEnglishSet(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    extern sLanguageDetails *gLanguageArray;
    extern U16 gCurrLangIndex;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_ENGLISH) == 0)
    {
        return 1;
    }

    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_AUTO) == 0)
    {
        return 1;
    }

    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  IsTrChineseSet
 * DESCRIPTION
 *  This function checks whether the current language is set as traditional
 *  Chinese or not.
 * PARAMETERS
 *  void
 * RETURNS
 *  On yes, return MMI_TRUE; otherwise, return MMI_FALSE.
 *****************************************************************************/
pBOOL IsTrChineseSet(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    extern sLanguageDetails *gLanguageArray;
    extern U16 gCurrLangIndex;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_TCHINESE) == 0)
    {
        return 1;
    }

    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  IsSmChineseSet
 * DESCRIPTION
 *  This function checks whether the current language is set as simplified
 *  Chinese or not.
 * PARAMETERS
 *  void
 * RETURNS
 *  On yes, return MMI_TRUE; otherwise, return MMI_FALSE.
 *****************************************************************************/
pBOOL IsSmChineseSet(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    extern sLanguageDetails *gLanguageArray;
    extern U16 gCurrLangIndex;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (strcmp((PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_SCHINESE) == 0)
    {
        return 1;
    }

    return 0;
}


void mmi_idle_update_opname_from_nitz(void)
{
    mmi_idle_notify_event();
}


pBOOL mmi_idle_is_on_idle_screen(void)
{
    return mmi_idle_is_active();
}


void EntryIdleScreen(void)
{
    mmi_idle_display();
}


void DisplayIdleScreen(void)
{
    mmi_idle_display();
}


void RedrawIdleScreen(void)
{
    /* do nothing. */
}



/*****************************************************************************
 * FUNCTION
 *  mmi_idle_get_dual_sim_status
 * DESCRIPTION
 *  Provide MMI level API for dual sim status (vendor request)
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_get_dual_sim_status(U8 *sim_status, U8* mode_status)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_DUAL_SIM_MASTER__
    if (mmi_bootup_is_sim_valid())
    {
        if (mmi_bootup_is_sim2_valid())
        {
            *sim_status = MMI_SIM_ID_DUAL_SIM;
        }
        else
        {
            *sim_status = MMI_SIM_ID_SIM1;
        }
    }
    else
    {
        if (mmi_bootup_is_sim2_valid())
        {
            *sim_status = MMI_SIM_ID_SIM2;
        }
        else
        {
            *sim_status = MMI_SIM_ID_NO_SIM;
        }
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    *sim_status = mmi_bootup_is_sim_valid() ? MMI_SIM_ID_SIM1 : MMI_SIM_ID_NO_SIM;
#endif /* __MMI_DUAL_SIM_MASTER__ */

#ifdef __MMI_DUAL_SIM_MASTER__
    switch(MTPNP_AD_Get_Startup_Mode())
    {
        case MTPNP_AD_NVRAM_CARD1:
            *mode_status = MMI_SIM_ID_SIM1;
        break;

        case MTPNP_AD_NVRAM_CARD2:
            *mode_status = MMI_SIM_ID_SIM2;
        break;

        case MTPNP_AD_NVRAM_FLIGHT:
            *mode_status = MMI_SIM_ID_FLIGHT_MODE;
        break;

        case MTPNP_AD_NVRAM_DUALCARD:
        default:
            *mode_status = MMI_SIM_ID_DUAL_SIM;
        break;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    *mode_status = mmi_bootup_get_active_flight_mode() ? MMI_SIM_ID_FLIGHT_MODE: MMI_SIM_ID_SIM1;
#endif /* __MMI_DUAL_SIM_MASTER__ */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_mms
 * DESCRIPTION
 *  Send message to MMS for SIM info notification
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_mms(void)
{
#ifdef OBIGO_Q03C_MMS_V02
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYQUEUE Message;
    mms_sim_info_notify_ind_struct *sim_info_notify_ind;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim_info_notify_ind = (mms_sim_info_notify_ind_struct *) OslConstructDataPtr(sizeof(mms_sim_info_notify_ind_struct));

#ifdef __MMI_DUAL_SIM_MASTER__
    if (mmi_bootup_is_sim_valid())
    {
        if (mmi_bootup_is_sim2_valid())
        {
            sim_info_notify_ind->sim_status = MMS_SIM_ID_DUAL_SIM;
        }
        else
        {
            sim_info_notify_ind->sim_status = MMS_SIM_ID_SIM1;
        }
    }
    else
    {
        if (mmi_bootup_is_sim2_valid())
        {
            sim_info_notify_ind->sim_status = MMS_SIM_ID_SIM2;
        }
        else
        {
            sim_info_notify_ind->sim_status = MMS_SIM_ID_NO_SIM;
        }
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->sim_status = mmi_bootup_is_sim_valid() ? MMS_SIM_ID_SIM1 : MMS_SIM_ID_NO_SIM;
#endif /* __MMI_DUAL_SIM_MASTER__ */

#ifdef __MMI_DUAL_SIM_MASTER__
    switch(MTPNP_AD_Get_Startup_Mode())
    {
        case MTPNP_AD_NVRAM_CARD1:
            sim_info_notify_ind->setting_mode = MMS_SIM_ID_SIM1;
        break;

        case MTPNP_AD_NVRAM_CARD2:
            sim_info_notify_ind->setting_mode = MMS_SIM_ID_SIM2;
        break;

        case MTPNP_AD_NVRAM_FLIGHT:
            sim_info_notify_ind->setting_mode = MMS_SIM_ID_FLIGHT_MODE;
        break;

        case MTPNP_AD_NVRAM_DUALCARD:
        default:
            sim_info_notify_ind->setting_mode = MMS_SIM_ID_DUAL_SIM;
        break;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->setting_mode = mmi_bootup_get_active_flight_mode() ? MMS_SIM_ID_FLIGHT_MODE: MMS_SIM_ID_SIM1;
#endif /* __MMI_DUAL_SIM_MASTER__ */

    Message.oslSrcId = MOD_MMI;
    Message.oslDestId = MOD_MMS;
    Message.oslMsgId = MSG_ID_MMS_SIM_INFO_NOTIFY_IND;
    Message.oslDataPtr = (oslParaType*) sim_info_notify_ind;
    Message.oslPeerBuffPtr = NULL;
    OslMsgSendExtQueue(&Message);
#endif /* OBIGO_Q03C_MMS_V02 */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_wap
 * DESCRIPTION
 *  Send message to WAP for SIM info notification
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_wap(void)
{
#ifdef WAP_SUPPORT
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYQUEUE Message;
    wap_sim_info_notify_ind_struct *sim_info_notify_ind;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim_info_notify_ind = (wap_sim_info_notify_ind_struct *) OslConstructDataPtr(sizeof(wap_sim_info_notify_ind_struct));

#ifdef __MMI_DUAL_SIM_MASTER__
    if (mmi_bootup_is_sim_valid())
    {
        if (mmi_bootup_is_sim2_valid())
        {
            sim_info_notify_ind->sim_status = WAP_SIM_ID_DUAL_SIM;
        }
        else
        {
            sim_info_notify_ind->sim_status = WAP_SIM_ID_SIM1;
        }
    }
    else
    {
        if (mmi_bootup_is_sim2_valid())
        {
            sim_info_notify_ind->sim_status = WAP_SIM_ID_SIM2;
        }
        else
        {
            sim_info_notify_ind->sim_status = WAP_SIM_ID_NO_SIM;
        }
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->sim_status = mmi_bootup_is_sim_valid() ? WAP_SIM_ID_SIM1 : WAP_SIM_ID_NO_SIM;
#endif /* __MMI_DUAL_SIM_MASTER__ */

    if (mmi_bootup_is_sim_removed())
    {
        sim_info_notify_ind->sim1_type = WAP_SIM_TYPE_UNKNOWN;
    }
    else if (!mmi_bootup_is_sim_valid())
    {
        sim_info_notify_ind->sim1_type = WAP_SIM_TYPE_BLOCKED_SIM;
    }
    else if (!mmi_bootup_is_nw_registration_ok())
    {
        sim_info_notify_ind->sim1_type = WAP_SIM_TYPE_INVALID_SIM;
    }
    else
    {
        sim_info_notify_ind->sim1_type = WAP_SIM_TYPE_VALID_SIM;
    }

#ifdef __MMI_DUAL_SIM_MASTER__
    if (mmi_bootup_is_sim2_removed())
    {
        sim_info_notify_ind->sim2_type = WAP_SIM_TYPE_UNKNOWN;
    }
    else if (!mmi_bootup_is_sim2_valid())
    {
        sim_info_notify_ind->sim2_type = WAP_SIM_TYPE_BLOCKED_SIM;
    }
    else if (!mmi_bootup_is_sim2_nw_registration_ok())
    {
        sim_info_notify_ind->sim2_type = WAP_SIM_TYPE_INVALID_SIM;
    }
    else
    {
        sim_info_notify_ind->sim2_type = WAP_SIM_TYPE_VALID_SIM;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->sim2_type = WAP_SIM_TYPE_UNKNOWN;
#endif /* __MMI_DUAL_SIM_MASTER__ */

#ifdef __MMI_DUAL_SIM_MASTER__
    switch(MTPNP_AD_Get_Startup_Mode())
    {
        case MTPNP_AD_NVRAM_CARD1:
            sim_info_notify_ind->setting_mode = WAP_SIM_ID_SIM1;
        break;

        case MTPNP_AD_NVRAM_CARD2:
            sim_info_notify_ind->setting_mode = WAP_SIM_ID_SIM2;
        break;

        case MTPNP_AD_NVRAM_FLIGHT:
            sim_info_notify_ind->setting_mode = WAP_SIM_ID_FLIGHT_MODE;
        break;

        case MTPNP_AD_NVRAM_DUALCARD:
        default:
            sim_info_notify_ind->setting_mode = WAP_SIM_ID_DUAL_SIM;
        break;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->setting_mode = mmi_bootup_get_active_flight_mode() ? WAP_SIM_ID_FLIGHT_MODE: WAP_SIM_ID_SIM1;
#endif /* __MMI_DUAL_SIM_MASTER__ */

    Message.oslSrcId = MOD_MMI;
    Message.oslDestId = MOD_WAP;
    Message.oslMsgId = MSG_ID_WAP_SIM_INFO_NOTIFY_IND;
    Message.oslDataPtr = (oslParaType*) sim_info_notify_ind;
    Message.oslPeerBuffPtr = NULL;
    OslMsgSendExtQueue(&Message);
#endif /* WAP_SUPPORT */

    mmi_idle_notify_dual_sim_status_to_mms();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_spa
 * DESCRIPTION
 *  Send message to SPA application for SIM info notification
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_spa(U8 sim_source)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYQUEUE Message;
    mmi_sim_status_info_ind_struct *sim_info_notify_ind;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    sim_info_notify_ind = (mmi_sim_status_info_ind_struct *) OslConstructDataPtr(sizeof(mmi_sim_status_info_ind_struct));

    sim_info_notify_ind->sim_id = sim_source;

#ifdef __MMI_DUAL_SIM_MASTER__
    if (!mmi_bootup_is_sim_removed())
    {
        if (!mmi_bootup_is_sim2_removed())
        {
            sim_info_notify_ind->sim_inserted = MMI_SIM_ID_DUAL_SIM;
        }
        else
        {
            sim_info_notify_ind->sim_inserted = MMI_SIM_ID_SIM1;
        }
    }
    else
    {
        if (!mmi_bootup_is_sim2_removed())
        {
            sim_info_notify_ind->sim_inserted = MMI_SIM_ID_SIM2;
        }
        else
        {
            sim_info_notify_ind->sim_inserted = MMI_SIM_ID_NO_SIM;
        }
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->sim_inserted = mmi_bootup_is_sim_valid() ? MMI_SIM_ID_SIM1 : MMI_SIM_ID_NO_SIM;
#endif /* __MMI_DUAL_SIM_MASTER__ */

    sim_info_notify_ind->sim1_can_read = mmi_bootup_is_sim_valid() ? MMI_TRUE : MMI_FALSE;

#ifdef __MMI_DUAL_SIM_MASTER__
    sim_info_notify_ind->sim2_can_read = mmi_bootup_is_sim2_valid() ? MMI_TRUE : MMI_FALSE;
#else
    sim_info_notify_ind->sim2_can_read = MMI_FALSE;
#endif

    if (mmi_bootup_is_sim_removed())
    {
        sim_info_notify_ind->sim1_type = MMI_SIM_TYPE_UNKNOWN;
    }
    else if (!mmi_bootup_is_sim_valid())
    {
        sim_info_notify_ind->sim1_type = MMI_SIM_TYPE_BLOCKED_SIM;
    }
    else if (!mmi_bootup_is_nw_registration_ok())
    {
        sim_info_notify_ind->sim1_type = MMI_SIM_TYPE_INVALID_SIM;
    }
    else
    {
        sim_info_notify_ind->sim1_type = MMI_SIM_TYPE_VALID_SIM;
    }

#ifdef __MMI_DUAL_SIM_MASTER__
    if (mmi_bootup_is_sim2_removed())
    {
        sim_info_notify_ind->sim2_type = MMI_SIM_TYPE_UNKNOWN;
    }
    else if (!mmi_bootup_is_sim2_valid())
    {
        sim_info_notify_ind->sim2_type = MMI_SIM_TYPE_BLOCKED_SIM;
    }
    else if (!mmi_bootup_is_sim2_nw_registration_ok())
    {
        sim_info_notify_ind->sim2_type = MMI_SIM_TYPE_INVALID_SIM;
    }
    else
    {
        sim_info_notify_ind->sim2_type = MMI_SIM_TYPE_VALID_SIM;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->sim2_type = MMI_SIM_TYPE_UNKNOWN;
#endif /* __MMI_DUAL_SIM_MASTER__ */

#ifdef __MMI_DUAL_SIM_MASTER__
    switch(MTPNP_AD_Get_Startup_Mode())
    {
        case MTPNP_AD_NVRAM_CARD1:
            sim_info_notify_ind->setting_mode = MMI_SIM_ID_SIM1;
        break;

        case MTPNP_AD_NVRAM_CARD2:
            sim_info_notify_ind->setting_mode = MMI_SIM_ID_SIM2;
        break;

        case MTPNP_AD_NVRAM_FLIGHT:
            sim_info_notify_ind->setting_mode = MMI_SIM_ID_FLIGHT_MODE;
        break;

        case MTPNP_AD_NVRAM_DUALCARD:
        default:
            sim_info_notify_ind->setting_mode = MMI_SIM_ID_DUAL_SIM;
        break;
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    sim_info_notify_ind->setting_mode = mmi_bootup_get_active_flight_mode() ? MMI_SIM_ID_FLIGHT_MODE: MMI_SIM_ID_SIM1;
#endif /* __MMI_DUAL_SIM_MASTER__ */

    Message.oslSrcId = MOD_MMI;
    Message.oslDestId = MOD_MMI;
    Message.oslMsgId = MSG_ID_MMI_SIM_STATUS_INFO_IND;
    Message.oslDataPtr = (oslParaType*) sim_info_notify_ind;
    Message.oslPeerBuffPtr = NULL;
    OslMsgSendExtQueue(&Message);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_spa_from_sim1
 * DESCRIPTION
 *  SPA wrapper
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_spa_from_sim1(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_idle_notify_dual_sim_status_to_spa(MMI_SIM_ID_SIM1);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_spa_from_sim2
 * DESCRIPTION
 *  SPA wrapper
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_spa_from_sim2(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_idle_notify_dual_sim_status_to_spa(MMI_SIM_ID_SIM2);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_dual_sim_status_to_spa_from_switch
 * DESCRIPTION
 *  SPA wrapper
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_dual_sim_status_to_spa_from_switch(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_idle_notify_dual_sim_status_to_spa(MMI_SIM_ID_DUAL_SIM);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_notify_bootup_ready_to_wap
 * DESCRIPTION
 *  Send message to WAP for idle screen notification
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_idle_notify_bootup_ready_to_wap(void)
{
}


/* For the detail information, please refer to IdleAppGprot.h */
MMI_BOOL mmi_idle_is_keypad_locked(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return mmi_scr_locker_is_locked();
}


/* Reset special function for special mode */
#if (defined(__MMI_ENGINEER_MODE__) || defined(__MMI_FACTORY_MODE__))
U8 gCurrentMode = NORMAL_MODE;
#endif

void DeInitSpecialMode(void)
{
#ifdef __MMI_ENGINEER_MODE__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (gCurrentMode == ENGINEERING_MODE)
    {
        gCurrentMode = NORMAL_MODE;
        mdi_audio_resume_background_play();
        StartLEDPatternBackGround();
    }
#endif /* __MMI_ENGINEER_MODE__ */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_idle_get_dial_pad_call_buffer
 * DESCRIPTION
 *  This function is the adapter function for the MTK identify. (Obsolete)
 * PARAMETERS
 *  void
 * RETURNS
 *  Dialer string if present.
 *****************************************************************************/
WCHAR *mmi_idle_get_dial_pad_call_buffer(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (WCHAR *)mmi_dialer_get_dial_string();
}


#if defined(__MMI_DIALER_SEARCH__)
/*
 * Adapter (Obsolete. Shall be removed later.)
 */
MMI_BOOL mmi_idle_ds_is_dialer_search_enable(void)
{
    return mmi_dialer_search_is_enable();
}


void mmi_idle_ds_set_dialer_search_enable(U8 is_enable)
{
    mmi_dialer_search_set_enable(is_enable);
}


void mmi_idle_ds_entry_toggle_dialer_search(void)
{
    mmi_dialer_search_entry_setting();
}
#endif /* defined(__MMI_DIALER_SEARCH__) */


void IdleRefreshServiceIndicationArea(void)
{
    mmi_idle_update_service_area();
}

